package com.ruoyi.note.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.note.domain.TBookKey;
import com.ruoyi.note.mapper.TBookKeyMapper;
import com.ruoyi.note.mapper.TBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.note.mapper.TBookContentMapper;
import com.ruoyi.note.domain.TBookContent;
import com.ruoyi.note.service.ITBookContentService;

/**
 * 内容Service业务层处理
 *
 * @author cl
 * @date 2021-04-15
 */
@Service
public class TBookContentServiceImpl implements ITBookContentService {
    @Autowired
    private TBookContentMapper tBookContentMapper;
    @Autowired
    private TBookMapper tBookMapper;

    /**
     * 查询内容
     *
     * @param id 内容ID
     * @return 内容
     */
    @Override
    public TBookContent selectTBookContentById(Long id) {
        return tBookContentMapper.selectTBookContentById(id);
    }

    @Override
    public int countAll(Long userId) {
        return tBookContentMapper.countAll(userId);
    }

    @Override
    public List<Map> addTrend(Long userId) {
        return tBookContentMapper.addTrend(userId);
    }

    /**
     * 查询内容列表
     *
     * @param tBookContent 内容
     * @return 内容
     */
    @Override
    public List<TBookContent> selectTBookContentList(TBookContent tBookContent) {
        return tBookContentMapper.selectTBookContentList(tBookContent);
    }

    /**
     * 新增内容
     *
     * @param tBookContent 内容
     * @return 结果
     */
    @Override
    public int insertTBookContent(TBookContent tBookContent) {
        tBookContent.setCreateTime(DateUtils.getNowDate());
        tBookMapper.updateTBookTime(tBookContent.getBookId());
        return tBookContentMapper.insertTBookContent(tBookContent);
    }

    /**
     * 修改内容
     *
     * @param tBookContent 内容
     * @return 结果
     */
    @Override
    public int updateTBookContent(TBookContent tBookContent) {
        tBookMapper.updateTBookTime(tBookContent.getBookId());
        return tBookContentMapper.updateTBookContent(tBookContent);
    }

    /**
     * 批量删除内容
     *
     * @param ids 需要删除的内容ID
     * @return 结果
     */
    @Override
    public int deleteTBookContentByIds(Long[] ids) {
        return tBookContentMapper.deleteTBookContentByIds(ids);
    }

    /**
     * 删除内容信息
     *
     * @param id 内容ID
     * @return 结果
     */
    @Override
    public int deleteTBookContentById(Long id) {
        return tBookContentMapper.deleteTBookContentById(id);
    }
}
